#!/usr/bin/env python
#!conding:utf-8
"""
author:Johnson
date: 2017/5/23 17:31
version: v1.0
description:
    默认打开页面
"""
from flask.blueprints import Blueprint
from flask_login.utils import login_required
from flask.templating import render_template
from blog import app
from blog.model import get_all
from blog.model.user_model import User
from tool import check_permission

user = Blueprint("user_view",__name__)

@user.route('/', methods = ['GET', 'POST'])
@user.route('/list', methods = ['GET', 'POST'])
@user.route('/list/<int:page>', methods = ['GET', 'POST'])
@login_required
@check_permission(2)
def index(page = 1):
    """
        分页demo ，error_out   表示内容为空时不报错
        @check_permission(2) 2:用户列表的permission
    :param page:
    :return:
    """
    pagination = User.query.paginate(page=page, per_page=app.config['SYSTEM_POSTS_PER_PAGE'], error_out=False)
    # users = get_all("select * from t_user")
    return render_template('user/user_list.html',users = pagination.items,pagination = pagination)



